package ar.com.notarip.bb.infosubte;

import java.util.Hashtable;
import java.util.Vector;

import net.rim.device.api.system.PersistentObject;
import net.rim.device.api.system.PersistentStore;


public class PersistentService {
	
	//ar.com.notarip.bb.infosubte.PersistentService --> 0x209169df1dfa2b7fL
	private static long STORE_CONFIGURATION_ID = 0x209169df1dfa2b7fL;
	private static PersistentObject _store = PersistentStore.getPersistentObject(STORE_CONFIGURATION_ID);

	

	public static Vector getOpciones(){

		
		return PersistentService.getOpciones("lineas");
		
		
	}
	
	public static Vector getOpciones(String key){

		
		Vector vec = null;
		
		PersistentService.refreshData();
		
		try{
			vec = (Vector)((Hashtable)_store.getContents()).get(key);
			
		}catch (Exception e){
			
			System.out.println(e.getMessage());
		}
		
		return vec;
		
	}


	public static void save(String key, Vector vec) {
		
		PersistentService.refreshData();	
		Hashtable map = (Hashtable) _store.getContents();
		
		map.remove(key);
		map.put(key, vec);
		
		PersistentService.save(map);
			
	}
	
	private static void save(Hashtable map) {
		
	       synchronized( _store )
	       { 
	           _store.setContents(map);
	           
	           
	       }
		
	}
	
	private static void refreshData(){
		
		Object obj = _store.getContents();
		
		if (!(obj instanceof Hashtable))
			_store.setContents(new Hashtable());
		
	}
	
	
	

}
